import pywinauto
from pywinauto import Application
# it is too damn long.
def recycle(app,listx):
    # always a list.
    # maybe the node is no longer there.
    # create a static shot instead.
    # think creating a COM service is fun?
    listx+=app
    # you don'd add these child up?
    # do it again and again.
    # game is a different place though.
    for x in app:
        print(x, type(x))
        z = x.children()
        if len(z)>0:
            print(type(z), z)
            recycle(z,listx)
    return listx
    # we can even get hidden shits.
# app = pywinauto.Application(backend="uia").connect(class_name="RootElement")
app = pywinauto.findwindows.find_elements(backend="uia", depth=0)
# and yes. here is the shit show.
# s=pywinauto.findwindows.enum_windows()
# listx=[]
listx=recycle(app,[])
print(len(listx),"THIS IS THE LENGTH OF IT.")
    # yes there are many language servers.
    # it doesn't matter.
    # you've got this.
    # whatever.
    # you want to try C# or Ruby, go ahead.
#     # v = pywinauto.handleprops.children(x)
#     v=pywinauto.handleprops.dumpwindow(x)
#     print(v)
    # does not work.
    # why you have so many handles?
    # try:
    #     app = pywinauto.Application(backend="uia").connect(handle=x,best_match=None)
    #     v = app.MainWindow.dump_tree()
    #     print(v)
    # except:
    #     print("Not found")
